const path = require('path');
const dotenv = require('dotenv');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');

const NODE_ENV = process.env.NODE_ENV === 'test' ? '.env.test' : '.env.development';
dotenv.config({ path: path.resolve(__dirname, NODE_ENV) });

module.exports = merge(common, {
        mode: 'development',
        devtool: 'cheap-module-source-map',
        output: {
            filename: '[name].js',
            path: path.resolve(__dirname, 'dist'),
        },
        cache: {
            type: 'memory',
        },
        module: {
            rules: [
                {
                    test: /\.css$/,
                    use: ['style-loader', 'css-loader'],
                },
                {
                    test: /\.scss$/,
                    use: ['style-loader', 'css-loader', 'sass-loader'],
                }
            ],
        },
        plugins: [
            new webpack.DefinePlugin({
                'process.env': JSON.stringify(process.env),
            }),
        ],
        devServer: {
            static: {
                directory: path.join(__dirname, 'dist'), // 指定静态文件目录
            },
            compress: true, // 启用压缩
            port: 8080, // 端口号
            hot: true, // 启用热模块替换
        }
    }
);

